package com.huynv.ochuvietnam;
import com.huynv.ochuvietnam.R;
//import com.huynv.ochuvietnam.viewWeb.showNewsFromUrlTask;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

public class viewWeb extends Activity{
	private WebView fullContent;
	private WebSettings fullContentsettings;
	ProgressBar Pbar;
	@Override
	protected void onCreate(Bundle savedInstanceState) {		
		super.onCreate(savedInstanceState);			
		setContentView(R.layout.view_detail);
		//actionBar = getActionBar();
		//actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
		//Log.e("viewWeb","ok1");
		Intent intent = getIntent();
		//Log.e("viewWeb","ok2");
//		link=intent.getStringExtra("link");
//		link=Utils.removeSC(link);
//		//Log.e("viewWeb","ok3, link="+link);
//		String id=intent.getStringExtra("id");
		
		Pbar = (ProgressBar) findViewById(R.id.pB1);
		fullContent = (WebView) findViewById(R.id.webview);	
		fullContent.getSettings().setSupportZoom(true);
        
    	fullContent.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    	fullContent.setScrollbarFadingEnabled(true);
    	fullContent.getSettings().setLoadsImagesAutomatically(true);        
    	fullContent.getSettings().setLoadWithOverviewMode(true);
		fullContent.getSettings().setUseWideViewPort(true);
		//.setUseWideViewPort(true);
		fullContent.getSettings().setBuiltInZoomControls(true);
		//fullContent.getSettings().setPluginState(PluginState.ON);
		//fullContent.setWebViewClient(new myWebClient());
		fullContent.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) 
            {
            if(progress < 100 && Pbar.getVisibility() == ProgressBar.GONE){
                Pbar.setVisibility(ProgressBar.VISIBLE);
                //txtview.setVisibility(View.VISIBLE);
            }
            Pbar.setProgress(progress);
            if(progress == 100) {
                Pbar.setVisibility(ProgressBar.GONE);
                //txtview.setVisibility(View.GONE);
            }
         }
		});
		
		//Log.e("onCreate", "ok3");
		fullContent.getSettings().setJavaScriptEnabled(true);
		fullContentsettings=fullContent.getSettings();
		
		//fullContentsettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		//fullContent.loadUrl("http://diemtinvietnam.vn/OChu/Play");
		new showNewsFromUrlTask().execute("http://diemtinvietnam.vn/OChu/Play");
       
	}
	private class showNewsFromUrlTask extends AsyncTask<String, Void, String> {    	
        @Override
        protected String doInBackground(String... urls) {              
            // params comes from the execute() call: params[0] is the url.
            try {
            	
        		//Log.e("onCreate", "ok4");
        		fullContent.loadUrl(urls[0]);
                return "1";	
            } catch (Exception e) {
            	Log.e("showNewsFromUrlTask", "can not download");
            	//dialog.dismiss();
            	//showExtProgram("Internet connection","Internet connection not available!");
            	//ResultDownloadWebpage=0;            	
            	return "0";
            }
        }
        
        // onPostExecute displays the results of the AsyncTask.
        @Override
        protected void onPostExecute(String result) {
            //textView.setText(result);
        	//try{
        		//if(dialog!=null) dialog.dismiss();
        	//}catch(Exception ex){
        		
        	//}
        	if (result.equals("0")){ 
        		Log.e("onPostExecute", "can not download");
        		//showExtProgram("Internet connection","Internet connection not available!");
        	}else{        		
        		Log.e("onPostExecute", "ok");
        	}
        	//try{
        		//if(dialog!=null) dialog.dismiss();
        	//}catch(Exception ex){
        		
        	//}
       }
    }
	public class myWebClient extends WebViewClient
	{
	
	     @Override
		 public void onPageStarted(WebView view, String url,Bitmap favicon) {
	      // TODO Auto-generated method stub
	      Log.e("onPageStarted", "ok1");
	      super.onPageStarted(view, url,favicon);	
	      Log.e("onPageStarted", "ok2");
	     }	 	
	     @Override	
	     public boolean shouldOverrideUrlLoading(WebView view, String url) {
	      // TODO Auto-generated method stub
	      Log.e("shouldOverrideUrlLoading", "ok1");
	      view.loadUrl(url);
	      Log.e("shouldOverrideUrlLoading", "ok2");
	      return true;
	     }
	     @Override	
	     public void onPageFinished(WebView view, String url) {
	      // TODO Auto-generated method stub
	      //Log.e("onPageFinished", "ok1");
	      super.onPageFinished(view, url);
	      //Log.e("onPageFinished", "ok2");
	      //progressBar.setVisibility(View.GONE);
	      //loading=false;
	      //dialog.dismiss();
	      //Log.e("onPageFinished", "ok3");
//	      fullContentsettings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);    		
//		  fullContentsettings.setUseWideViewPort(false);
//		  is_Single_Colunm=true;
	     }
	  }
}
